package net.lzzy.kvrdd;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaPairRDD;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.PairFunction;
import scala.Tuple2;

import java.util.Arrays;

public class MapToPair {
    public static void main(String[] args) {
        SparkConf conf = new SparkConf().setAppName("MapToPair").setMaster("local");
        JavaSparkContext jsc = new JavaSparkContext(conf);
        JavaRDD<String> parallelize = jsc.parallelize(Arrays.asList(
                "1111-11-11,11", "2222-22-22,22", "3333-33-33,33"));
        JavaPairRDD<String, String> sjp = parallelize.mapToPair(new PairFunction<String, String, String>() {
            @Override
            public Tuple2<String, String> call(String s) throws Exception {
                System.out.println(".......");
                return new Tuple2<>(s.split(",")[0], s);
            }
        });

        System.out.println(sjp.collect());
    }

}
